﻿using System;
using EQATEC.Analytics.Monitor;

namespace Hibiku.Services
{

    public class EqatecAnalyticsFeatureTrackingService : IFeatureTrackingService, IDisposable
    {
        private readonly IAnalyticsMonitor _analyticsMonitor;

        public EqatecAnalyticsFeatureTrackingService()
        {
            var settings = new AnalyticsMonitorSettings(Constants.EqatecAnalyticsKey);

            _analyticsMonitor = EQATEC.Analytics.Monitor.AnalyticsMonitorFactory.Create(settings);
            _analyticsMonitor.Start();
        }

        #region IFeatureTrackingService Members

        public void TrackFeature(string featureName)
        {
            _analyticsMonitor.TrackFeature(featureName);
        }

        public void TrackException(Exception exception, string contextMessage, params object[] args)
        {
            _analyticsMonitor.TrackException(exception, contextMessage, args);
        }

        public void Log(string messageFormat, params object[] args)
        {
            _analyticsMonitor.SendLog(messageFormat, args);
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            _analyticsMonitor.Stop();
        }

        #endregion
    }
}
